package com.yu.gulimall.ware.dao;

import com.yu.gulimall.ware.entity.WareSkuEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 商品库存
 *
 * @author yfy
 * @email HeJieLin@gulimall.com
 * @date 2024-06-16 21:49:11
 */
@Mapper
public interface WareSkuDao extends BaseMapper<WareSkuEntity> {

    @Update("update wms_ware_sku set stock=stock+#{skuNum} where sku_id=#{skuId} and ware_id = #{wareId}")
    void addStock(@Param("skuId") Long skuId,@Param("wareId") Long wareId,@Param("skuNum") Integer skuNum);

    @Select("select sum(stock-stock_locked) from wms_ware_sku where sku_id = #{item}")
    Long getSkuStock(@Param("item") Long item);

    List<Long> listWareIdHasSkuStock(Long skuId);

    Long lockSkuStock(Long skuId, Long wareId, Integer num);

    void unLockStock(Long skuId, Long wareId, Integer num);
}
